package com.leyou.common.advice;

import com.leyou.common.exceptions.LyException;
import com.leyou.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author hcz
 * @describtion TODO
 * @date 2019-06-22 21:33
 */
@ControllerAdvice //controller里面抛出的任何异常都会被这里处理
public class BaseExceptionAdvice {

    @ExceptionHandler(LyException.class) //异常处理器，声明处理何种异常
    public ResponseEntity<ExceptionResult> handlerException(LyException e){

        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }
}
